﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Hutech.CRM.Library.Views;
using nvn.Core.MVP;
using Hutech.CRM.Library.Models.Entities;
using Hutech.CRM.Library.Models.BusinessAccessLayer.BusinessObjects;
using Hutech.CRM.Library.Models.BusinessAccessLayer;
using nvn.Library.Patterns;
using Hutech.CRM.Library.Utilities;

namespace Hutech.CRM.Library.Presenters
{
    public class AddNewLoaiDanhMucPresenter : BasePresenter<IAddNewLoaiDanhMucView>
    {
        public AddNewLoaiDanhMucPresenter(IAddNewLoaiDanhMucView view)
            : base(view)
        {
            view.Save_Click += new EventHandler<SaveEventAgrs<DanhMucThongTin>>(view_Save_Click);
        }

        void view_Save_Click(object sender, SaveEventAgrs<DanhMucThongTin> e)
        {
            IDanhMucThongTinBAL item = new DanhMucThongTinBAL();
            DanhMucThongTin loaiDanhMuc = e.myType;
            loaiDanhMuc.LoaiDanhMucName = ConstantVariable.VALUE_DEFAULT_SYMBOL_ROOT;
            if (!item.CheckExitLoaDanhMuc(loaiDanhMuc.DanhMucName, loaiDanhMuc.DanhMucGuid))
            {
                if (item.Save(loaiDanhMuc))
                {
                    view.ErrorMessage = "Thêm loại danh mục thành công";
                    view.CallBack();
                }
                else
                    view.ErrorMessage = "Thực hiện thất bại";
            }
            else
                view.ErrorMessage = "Loại danh mục đã tồn tại";
        }
    }
}
